<?php namespace Home\Controller;
use Hdphp\Controller\Controller;

class ListController extends Controller{
	
	public function index(){
		$cid = Q('get.cid',0,'intval');
		$tid = Q('get.tid',0,'intval');
		$tagModel = new \Common\Model\Tag;
		if($cid){
			//设置name
			$name = "分档归类";
			//实例化分类模型
			$cateModel = new \Common\Model\Cate;
			$value = $cateModel->where("cid={$cid}")->pluck('cname');
			
			$cids = $cateModel->getScate($cateModel->get(),$cid);
			$cids[]=$cid;
			
			$arcModel = new \Common\Model\Arc;
			
			$count = $arcModel->where("category_cid in (".implode(",", $cids).")")->count();
			
			$data = Db::table('article')
					->join('category','category_cid','=','cid')
					->where("category_cid in (".implode(",", $cids).")")
					->get();
			
			$data = $tagModel->getTag($data);	
		}
		
		if($tid){
			//设置name
			$name = "标签";
			$value = $tagModel->where("tid={$tid}")->pluck('tname');
			$arcTagModel = new \Common\Model\Arctag;
			$count = $arcTagModel->where("tag_tid={$tid}")->count();
			$data = Db::table('article_tag')
					->join('article','article_aid','=','aid')
					->join('category',"category_cid",'=','cid')
					->where("tag_tid={$tid}")
					->get();
			$data = $tagModel->getTag($data);
		}

		View::with("name",$name);
		View::with("value",$value);
		View::with("count",$count);
		View::with("data",$data);
			
		View::make();
	}
	
}





 ?>